package com.sxyjhh;

import com.robert.kafka.kclient.core.KafkaConsumer;
import com.robert.kafka.kclient.handlers.SafelyMessageHandler;
import com.sxyjhh.common.DBConfig;
import com.sxyjhh.create.api.DataApi;
import com.sxyjhh.dbutil.basic.ConstConfig;
import com.sxyjhh.dbutil.basic.DBQueryUtils;
import com.sxyjhh.dbutil.utils.CommonUtils;
import com.sxyjhh.dbutil.utils.DBInfoUtil;
import com.sxyjhh.schedule.TaskSchedulerManager;
import com.sxyjhh.service.data_exchange.DataExchangeService;
import com.sxyjhh.service.data_exchange.ImageService;
import com.sxyjhh.service.data_exchange.PollingRunnable;
import com.sxyjhh.service.data_exchange.PollingRunnableQyxy;
import com.sxyjhh.utils.FtpUtil;
import com.sxyjhh.utils.IdGenerator;
import com.sxyjhh.utils.redis.RedisOperator;
import com.sxyjhh.utils.util.XaUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

import java.io.IOException;
import java.sql.SQLException;
import java.util.*;

/**
 * Created by Administrator on 2018/6/28.
 */
@Component
public class InitStartProc implements CommandLineRunner {

    @Autowired
    private DataExchangeService dataExchangeService;

    @Autowired
    private ImageService imageService;

    private FTPClient ftpClient = new FTPClient();

    private Map<String, String> dicMap;

   /* @Autowired
    public Jedis jedis;*/

   @Autowired
   private JedisCluster jedisCluster;

    @Autowired
    private RedisOperator redisOperator;

    @Autowired
    private TaskSchedulerManager taskSchedulerManager;


    private String ip = DBConfig.readPop("output.datasource.ip");
    private String dbName = DBConfig.readPop("output.datasource.db.name");
    private String userName = DBConfig.readPop("output.datasource.username");
    private String password = DBConfig.readPop("output.datasource.password");
    private String port = DBConfig.readPop("output.datasource.port");
    private String dbSType = DBConfig.readPop("output.datasource.type");
    private String dicTableName = DBConfig.readPop("DIC.TABNAME");

    private String recordIp = DBConfig.readPop("output.record.ip");
    private String recordDbName = DBConfig.readPop("output.record.db.name");
    private String recordUserName = DBConfig.readPop("output.record.username");
    private String recordPassword = DBConfig.readPop("output.record.password");
    private String recordPort = DBConfig.readPop("output.record.port");
    private String recordDbSType = DBConfig.readPop("output.record.type");


    private String safetyTabName = DBConfig.readPop("COMPANY.SAFETY.CERTIFICATE.OUT");
    private String personTabName = DBConfig.readPop("PERSON.SECURITY.CERTIFICATE.OUT");
    private String imagesTabName = DBConfig.readPop("PERSON.IMAGES.OUT");
    private static final Logger logger = Logger.getLogger(InitStartProc.class);

    private int ZJNUM = 0;
    private int RYNUM = 0;


    private void dateListence() {
        String safetyTabNameOUT = safetyTabName.substring(safetyTabName.indexOf(".") + 2, safetyTabName.length() - 1);
        String personTabNameOUT = personTabName.substring(personTabName.indexOf(".") + 2, personTabName.length() - 1);
        String imagesTabNameOUT = imagesTabName.substring(imagesTabName.indexOf(".") + 2, imagesTabName.length() - 1);
        String url = "";
        ConstConfig.DBType dbType = ConstConfig.DBType.valueOf(Integer.valueOf(dbSType));
        if ("3".equals(dbSType)) {
            url = "jdbc:mysql://192.168.2.201:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&useSSL=false";
        } else {
            url = DBInfoUtil.getDBUrl(dbType, ip, port, dbName);
        }

        DBQueryUtils dbQueryUtils = new DBQueryUtils(DBInfoUtil.getDBDriverName(dbType),
                url, userName, password, 5);


        KafkaConsumer kafkaConsumerZJ = new KafkaConsumer(
                "kafka-consumer.properties", safetyTabNameOUT, 1, new SafelyMessageHandler() {
            @Override
            protected void doExecute(String s) {
                net.sf.json.JSONObject jsonObject = null;
                String pushData = "";
                jsonObject = net.sf.json.JSONObject.fromObject(s);
                String fid = jsonObject.get("COMPANY_SAFETY_CERTIFICATE_ID") + "";
                String zszt = "无效".equals(jsonObject.get("CERTIFICATE_STATE") + "") ? "04" : "有效".equals(jsonObject.get("CERTIFICATE_STATE") + "") ? "01" : jsonObject.get("CERTIFICATE_STATE") + "";
                jsonObject.put("CERTIFICATE_STATE", zszt);
                pushData = "{'COMPANY_SAFETY_CERTIFICATE':" + jsonObject.toString() + "}";
                logger.info(pushData);
                ZJNUM += 1;
                logger.info("接收数量：");
                logger.info(ZJNUM + "");
                try {
                   // taskSchedulerManager.onlyOneTime(new PollingRunnableQyxy(fid, safetyTabNameOUT, pushData, ZJNUM));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        KafkaConsumer kafkaConsumerRY = new KafkaConsumer(
                "kafka-consumer.properties", personTabNameOUT, 1, new SafelyMessageHandler() {
            @Override
            protected void doExecute(String s) {
                net.sf.json.JSONObject jsonObject = null;
                String pushData = "";
                String result = "";

                try {
                    FtpUtil.getInstance().connect(ftpClient, "192.168.2.180", 2121, "yjhh", "a1b2c3d4!");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                jsonObject = net.sf.json.JSONObject.fromObject(s);
                String fid = jsonObject.get("PERSON_SECURITY_CERTIFICATE_ID") + "";

                jsonObject.put("ID_CARDS_TYPE", getDicCode(jsonObject.get("ID_CARDS_TYPE") + "", "zj"));
                jsonObject.put("EDULEVEL", getDicCode(jsonObject.get("EDULEVEL") + "", "xl"));
                jsonObject.put("PERSON_TYPE", getDicCode(jsonObject.get("PERSON_TYPE") + "", "ry"));
                jsonObject.put("CERTIFICATE_AUTHORITY", "陕西省住房和城乡建设厅");
                jsonObject.put("CERTIFICATE_STATE", getDicCode(jsonObject.get("CERTIFICATE_STATE") + "", "zt"));

                List data = null ;
                try {
                    data = dbQueryUtils.queryData("select FCONTENT as path  from " + imagesTabName + " where FLINKID ='" + fid + "'");
                } catch (SQLException e) {
                    e.printStackTrace();
                    errorRecord( "{'PERSON_SECURITY_CERTIFICATE':" + jsonObject.toString() + "}", "queryTableError", personTabNameOUT);
                }
                String image = "";
                if (!XaUtil.isEmpty(data)) {
                    net.sf.json.JSONObject countJson = net.sf.json.JSONObject.fromObject(data.get(0));
                    String path = (String) countJson.get("PATH");
                    image = ftpDownload(path);
                }

                jsonObject.put("PHOTO", image);
                pushData = "{'PERSON_SECURITY_CERTIFICATE':" + jsonObject.toString() + "}";
                logger.info(pushData);
                RYNUM += 1;
                logger.info("接收数量：");
                logger.info(RYNUM + "");
                try {
                    //taskSchedulerManager.onlyOneTime(new PollingRunnable(fid, personTabNameOUT, pushData, RYNUM));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        KafkaConsumer kafkaConsumerTP = new KafkaConsumer(
                "kafka-consumer.properties", imagesTabNameOUT, 1, new SafelyMessageHandler() {
            @Override
            protected void doExecute(String s) {
                net.sf.json.JSONObject jsonObject = null;
                String pushData = "";
                try {
                    FtpUtil.getInstance().connect(ftpClient, "192.168.2.180", 2121, "yjhh", "a1b2c3d4!");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                jsonObject = net.sf.json.JSONObject.fromObject(s);
                String path = (String) jsonObject.get("FCONTENT");
                String personId = jsonObject.get("FLINKID") + "";

                List data = null;
                try {
                    data = dbQueryUtils.queryData("select *  from " + personTabName + " where FID ='" + personId + "'");
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                net.sf.json.JSONObject jsonObjectBsae = null;
                String image = "";
                Map<String, Object> resMap = new HashMap<>();
                if (!XaUtil.isEmpty(data)) {
                    Map<String, Object> obj = (Map<String, Object>) data.get(0);
                    obj.remove("FTXT1");
                    obj.remove("FTXT2");
                    obj.remove("FTXT3");
                    obj.remove("FTXT4");
                    obj.remove("FTXT5");
                    jsonObjectBsae = net.sf.json.JSONObject.fromObject(obj);

                    pollingData(jsonObjectBsae, resMap, new Date());
                    image = ftpDownload(path);
                    if (!XaUtil.isEmpty(image)) {
                        resMap.put("PHOTO", image);
                        resMap.put("OPERATION_FLAG", "U");
                        resMap.put("PHOTO", image);

                        resMap.put("ID_CARDS_TYPE", getDicCode(jsonObject.get("ID_CARDS_TYPE") + "", "zj"));
                        resMap.put("EDULEVEL", getDicCode(jsonObject.get("EDULEVEL") + "", "xl"));
                        resMap.put("PERSON_TYPE", getDicCode(jsonObject.get("PERSON_TYPE") + "", "ry"));
                        resMap.put("CERTIFICATE_AUTHORITY", "陕西省住房和城乡建设厅");
                        resMap.put("CERTIFICATE_STATE", getDicCode(jsonObject.get("CERTIFICATE_STATE") + "", "zt"));
                        pushData = "{'PERSON_SECURITY_CERTIFICATE':" + net.sf.json.JSONObject.fromObject(resMap).toString() + "}";
                        logger.info(pushData);
                        RYNUM += 1;
                        logger.info("接收数量：");
                        logger.info(RYNUM + "");

                        try {
                           // taskSchedulerManager.onlyOneTime(new PollingRunnable(personId + "", imagesTabName, pushData, RYNUM));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        try {
            kafkaConsumerZJ.startup();
            kafkaConsumerRY.startup();
            kafkaConsumerTP.startup();
            try {
                System.in.read();
                System.out.println("Read the exit command.");
            } catch (IOException e) {
                e.printStackTrace();
            }
        } finally {
            System.out.println("Start to exit...");
            kafkaConsumerZJ.shutdownGracefully();
            kafkaConsumerRY.shutdownGracefully();
            kafkaConsumerTP.shutdownGracefully();
        }
    }


    private void dataDelete() {
        String safetyTabNameOUT = safetyTabName.substring(safetyTabName.indexOf(".") + 2, safetyTabName.length() - 1);
        String personTabNameOUT = personTabName.substring(personTabName.indexOf(".") + 2, personTabName.length() - 1);
        String imagesTabNameOUT = imagesTabName.substring(imagesTabName.indexOf(".") + 2, imagesTabName.length() - 1);
        String url = "";
        ConstConfig.DBType dbType = ConstConfig.DBType.valueOf(Integer.valueOf(dbSType));
        if ("3".equals(dbSType)) {
            url = "jdbc:mysql://192.168.2.201:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&useSSL=false";
        } else {
            url = DBInfoUtil.getDBUrl(dbType, ip, port, dbName);
        }

        DBQueryUtils dbQueryUtils = new DBQueryUtils(DBInfoUtil.getDBDriverName(dbType),
                url, userName, password, 5);


        KafkaConsumer kafkaConsumerZJ = new KafkaConsumer(
                "kafka-consumer.properties", safetyTabNameOUT, 1, new SafelyMessageHandler() {
            @Override
            protected void doExecute(String s) {
                System.out.println(s);
            }
        });

        KafkaConsumer kafkaConsumerRY = new KafkaConsumer(
                "kafka-consumer.properties", personTabNameOUT, 1, new SafelyMessageHandler() {
            @Override
            protected void doExecute(String s) {
                System.out.println(s);
            }
        });

        KafkaConsumer kafkaConsumerTP = new KafkaConsumer(
                "kafka-consumer.properties", imagesTabNameOUT, 1, new SafelyMessageHandler() {
            @Override
            protected void doExecute(String s) {
                System.out.println(s);
            }
        });
        try {
            kafkaConsumerZJ.startup();
            kafkaConsumerRY.startup();
            kafkaConsumerTP.startup();
            try {
                System.in.read();
                System.out.println("Read the exit command.");
            } catch (IOException e) {
                e.printStackTrace();
            }
        } finally {
            System.out.println("Start to exit...");
            kafkaConsumerZJ.shutdownGracefully();
            kafkaConsumerRY.shutdownGracefully();
            kafkaConsumerTP.shutdownGracefully();
        }
    }

    @Override
    public void run(String... strings) throws Exception {

      /*  dicMap = new HashMap<>();

        DataApi ri = new DataApi(DBConfig.readPop("daq.task.pconnect.url"));
        List<String> dicList = ri.selectDataQ("select FNUMBER,FNAME from " + dicTableName);

        if (!XaUtil.isEmpty(dicList)) {
            for (String dic : dicList) {
                String[] dicArray = dic.split("&&");
                dicMap.put(dicArray[0], dicArray[1]);
            }
        }*/
      /*  int i = delRedisData(personTabName);
        System.out.println(i);*/
      /*  new Thread() {
            @Override
            public void run() {
                dataExchangeService.startSynDataRy();
            }
        }.start();*/

   /*     new Thread() {
            @Override
            public void run() {dateListence();
            }
        }.start();
        new Thread() {
            @Override
            public void run() {
                dataExchangeService.startSynData();
            }
        }.start();*/
     /*   new Thread() {
            @Override
            public void run() {
                //imageService.startSynDataTP();
                dataExchangeService.startSynData();
            }
        }.start();*/
      /*  new Thread() {
            @Override
            public void run() {
                dataExchangeService.startSynData();
            }
        }.start();*/
      /*  new Thread() {
            @Override
            public void run() {
                dataExchangeService.startSynDataRy();
            }
        }.start();*/

    /*    new Thread() {
            @Override
            public void run() {
                imageService.startSynDataTP();
            }
        }.start();*/
    }


    private void imagePush() {

        String url;
        ConstConfig.DBType dbType = ConstConfig.DBType.valueOf(Integer.valueOf(dbSType));
        if ("3".equals(dbSType)) {
            url = "jdbc:mysql://192.168.2.201:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&useSSL=false";
        } else {
            url = DBInfoUtil.getDBUrl(dbType, ip, port, dbName);
        }

        DBQueryUtils dbQueryUtils = new DBQueryUtils(DBInfoUtil.getDBDriverName(dbType),
                url, userName, password, 5);

        String pushData = "";
        try {
            FtpUtil.getInstance().connect(ftpClient, "192.168.2.180", 2121, "yjhh", "a1b2c3d4!");
        } catch (IOException e) {
            e.printStackTrace();
        }

        List countList = null;
        int outCount = 0;
        try {
            countList = dbQueryUtils.queryData("select count(1) as CUT from " + imagesTabName);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (!XaUtil.isEmpty(countList)) {
            net.sf.json.JSONObject countJson = net.sf.json.JSONObject.fromObject(countList.get(0));
            outCount = Integer.parseInt(countJson.get("CUT") + "");
        }

        int num = 3000;
        int batch = (outCount / num) + (outCount % num != 0 ? 1 : 0);

        for (int i = 1; i < batch; i++) {
            try {
                int y = ((i + 1) * num) - num;
                List data = dbQueryUtils.queryData("select * from (select rownum r, b.*,a.FCONTENT  from SLRY.\"daq_cf_pub_text\" a, SLRY.\"daq_cf_person_baseinfo\" b where a.FLINKID = b.FID and rownum<=" + (i + 1) * num + ") where r>" + y);

                net.sf.json.JSONObject jsonObjectBsae = null;
                String image = "";
                Map<String, Object> resMap = new HashMap<>();
                if (!XaUtil.isEmpty(data)) {
                    for (Object da : data) {
                        Map<String, Object> obj = (Map<String, Object>) da;
                        obj.remove("FTXT1");
                        obj.remove("FTXT2");
                        obj.remove("FTXT3");
                        obj.remove("FTXT4");
                        obj.remove("FTXT5");

                        String path = (String) obj.get("FCONTENT");
                        jsonObjectBsae = net.sf.json.JSONObject.fromObject(obj);

                        pollingData(jsonObjectBsae, resMap, new Date());
                        image = ftpDownload(path);
                        if (!XaUtil.isEmpty(image)) {
                            resMap.put("PHOTO", image);
                            resMap.put("OPERATION_FLAG", "U");
                            resMap.put("PHOTO", image);

                            resMap.put("ID_CARDS_TYPE", getDicCode(resMap.get("ID_CARDS_TYPE") + "", "zj"));
                            resMap.put("EDULEVEL", getDicCode(resMap.get("EDULEVEL") + "", "xl"));
                            resMap.put("PERSON_TYPE", getDicCode(resMap.get("PERSON_TYPE") + "", "ry"));
                            resMap.put("CERTIFICATE_AUTHORITY", "陕西省住房和城乡建设厅");
                            resMap.put("CERTIFICATE_STATE", getDicCode(resMap.get("CERTIFICATE_STATE") + "", "zt"));

                            pushData = "{'PERSON_SECURITY_CERTIFICATE':" + net.sf.json.JSONObject.fromObject(resMap).toString() + "}";
                            System.out.println(pushData);
                            RYNUM += 1;
                            System.out.println("接收数量：");
                            System.out.println(RYNUM);
                            try {
                               // taskSchedulerManager.onlyOneTime(new PollingRunnable(resMap.get("FID") + "", imagesTabName, pushData, RYNUM));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    private String ftpDownload(String path) {


        String imgBase64 = "";
        try {
            byte[] imageByte = FtpUtil.getInstance().download(ftpClient, path);
            if (!XaUtil.isEmpty(imageByte)) {
                imgBase64 = Base64.encodeBase64String(imageByte);
                return imgBase64;
            } else {
                return imgBase64;
            }

        } catch (IOException e) {
            e.printStackTrace();
            return imgBase64;
        }
    }

    private String getDicCode(String s, String type) {
        String dicCode = "";

        if ("ry".equals(type)) {
            if ("C证人员".equals(s)) {
                dicCode = "03";
            }
            if ("C3证人员".equals(s)) {
                dicCode = "06";
            }
            if ("C2证人员".equals(s)) {
                dicCode = "05";
            }
            if ("C1证人员".equals(s)) {
                dicCode = "04";
            }
            if ("B证人员".equals(s)) {
                dicCode = "02";
            }
            if ("A证人员".equals(s)) {
                dicCode = "01";
            }

        }

        if ("zj".equals(type)) {
            if ("身份证".equals(s)) {
                dicCode = "01";
            }
            if ("军官证".equals(s)) {
                dicCode = "02";
            }
            if ("其他".equals(s)) {
                dicCode = "99";
            }
        }
        if ("zt".equals(type)) {
            if ("2".equals(s)) {
                dicCode = "01";
            }
            if ("-1".equals(s)) {
                dicCode = "04";
            }
        }
        if ("xl".equals(type)) {
            if ("博士".equals(s) || "博士后".equals(s)) {
                dicCode = "01";
            }
            if ("无".equals(s)) {
                dicCode = "99";
            }

            if ("大专".equals(s)) {
                dicCode = "04";
            }
            if ("中专".equals(s)) {
                dicCode = "05";
            }
            if ("本科".equals(s)) {
                dicCode = "03";
            }
            if ("中专以下(含高中初中)".equals(s)) {
                dicCode = "06";
            }
            if ("硕士".equals(s)) {
                dicCode = "02";
            }
        }
        return dicCode;
    }


    private void pollingData(Map<String, Object> map, Map<String, Object> resMap, Date date) {

        String sex = map.get("FSEX") + "";
        if (!StringUtils.isBlank(sex)) {
            sex = "男".equals(sex) ? "01" : "女".equals(sex) ? "02" : "";
        }
        resMap.put("PERSON_SECURITY_CERTIFICATE_ID", map.get("FID"));
        resMap.put("PROVICE_CODE", "610000");
        resMap.put("NAME", map.get("FNAME"));
        resMap.put("ID_CARDS_TYPE", !XaUtil.isEmpty(map.get("FIDCARDTYPEID")) ? dicMap.get(map.get("FIDCARDTYPEID")) : "");
        resMap.put("ID_CARDS_NUMBER", map.get("FIDCARD"));
        resMap.put("SEX", sex);
        resMap.put("BIRTHDAY", dateFormat(map.get("FBIRTHDAY")));
        resMap.put("EDULEVEL", !XaUtil.isEmpty(map.get("FDEGREEID")) ? dicMap.get(map.get("FDEGREEID")) : "");
        resMap.put("PHOTO", "");
        resMap.put("PERSON_TYPE", !XaUtil.isEmpty(map.get("FPERSONTYPEID")) ? dicMap.get(map.get("FPERSONTYPEID")) : "");
        resMap.put("COMPANY_NAME", map.get("FBASENAME"));
        resMap.put("COMPANY_CREDIT_CODE", map.get("FJURIDCIALCODE"));
        resMap.put("POST", map.get("FFUNCTION"));
        resMap.put("POSITIONAL_TITLE", "");
        resMap.put("CERTIFICATE_NUMBER", map.get("FCERTINO"));
        resMap.put("CERTIFICATE_START_DATE", dateFormat(map.get("FBEGINTIME")));
        resMap.put("CERTIFICATE_END_DATE", dateFormat(map.get("FENDTIME")));
        resMap.put("CERTIFICATE_AUTHORITY", "陕西省住房和城乡建设厅");
        resMap.put("CERTIFICATE_SEND_DATE", dateFormat(map.get("FAPPTIME")));
        resMap.put("CERTIFICATE_CONTINUE_DATE", "");
        resMap.put("CERTIFICATE_STATE", map.get("FSTATE"));
        resMap.put("ELECTRONIC_CERTIFICATES", "");
        resMap.put("OPERATION_FLAG", map.get("OPERATION_FLAG"));
        resMap.put("CREATEDATE", CommonUtils.YYYYMMDD.format(date));
        resMap.put("CERTIFICATE_RECHECK_DATE", "");
        resMap.put("OPERATE_TYPE", "");
    }

    private String dateFormat(Object time) {
        if (XaUtil.isEmpty(time)) {
            return null;
        }
        String dateFormat = time + "";
        return dateFormat.substring(0, 10);
    }

    private void errorRecord(String json, String resCode, String tableName) {
        String url = "";
        ConstConfig.DBType dbType = ConstConfig.DBType.valueOf(Integer.valueOf(recordDbSType));
        if ("3".equals(recordDbSType)) {
            url = "jdbc:mysql://" + recordIp + ":" + recordPort + "/" + recordDbName + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&useSSL=false";
        } else {
            url = DBInfoUtil.getDBUrl(dbType, recordIp, recordPort, recordDbName);
        }

        DBQueryUtils dbQueryUtils = new DBQueryUtils(DBInfoUtil.getDBDriverName(dbType),
                url, recordUserName, recordPassword, 5);

        List<Map<String, Object>> dataList = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("id", IdGenerator.createNewId());
        map.put("task_id", "");
        map.put("time", CommonUtils.YYYYMMDDHHMMSS.format(new Date()));
        map.put("error_message", resCode);
        map.put("error_data", json);
        map.put("table_name", tableName);
        dataList.add(map);
        try {
            dbQueryUtils.insertBatchData("data_exchange_error", recordDbName, dataList);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    //删除信息
    public int delRedisData(String tabName) {
        //删除记录
        Set<String> set = redisOperator.keys(tabName + "*");
        int i = 0;
        if (!XaUtil.isEmpty(set)) {
            for (String redisKey : set) {
                i += jedisCluster.del(redisKey);
            }
        }
        return i;
    }

}
